package com.supinfo.food.services;


import java.util.List;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;

import com.supinfo.food.dao.DaoFactory;
import com.supinfo.food.dao.DishDao;
import com.supinfo.food.entities.Dish;

/**
 * Customer service
 * @author Keitaro
 */
@WebService(name="Dish", serviceName="Dish")
public class DishService {

	private DishDao dao = DaoFactory.getDishDao();
	
	@WebMethod(operationName="addDish")
	public Dish	addDish(@WebParam(name="dish") Dish dish) {
		return dao.addDish(dish);
	}

	@WebMethod(operationName="updateDish")
	public Dish	updateDish(@WebParam(name="dish") Dish dish) {
		return dao.updateDish(dish);
	}

	@WebMethod(operationName="getAllDish")
	public Dish[]	getAllDish() {
		List<Dish> list = dao.getAllDishes();
		if (list == null || list.isEmpty())
			return null;
		return list.toArray(new Dish[1]);
	}
	
	@WebMethod(operationName="getDishById")
	public Dish getDishById(@WebParam(name="id") Long id) {
		return dao.findDish(id);
	}

	@WebMethod(operationName="removeDish")
	public void removeDish(@WebParam(name="id") Long id) {
		dao.delete(id);
	}
	
}
